#ifndef __CBUFFER_H__
#define __CBUFFER_H__

#include <string>
#include <WString.h>

class CBuffer{
public:
    CBuffer(int size);

    ~CBuffer();

    bool push(const char * data, int size);

    bool push(std::string & str);

    bool push(String & str);

    void pop(int size);

    void clear();

    int operator<<(int sockfd);

    int operator>>(int sockfd);

    bool operator<<(std::string & str);

    bool operator<<(String & str);

    int size(){
        return m_buffer_data_size;
    }

    bool has_data(){
        return m_buffer_data_size > 0;
    }

    char * c_str(){
        return m_buffer;
    }
private:
    //数据指针
    char * m_buffer = nullptr;
    //已有数据长度
    int m_buffer_data_size = 0;
    //buffer缓冲大小
    int m_buffer_size = 0;
};

#endif
